﻿using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using IQKS.AWP.BusinessAccessLayer;
using IQKS.AWP.BusinessObject;
using System.Data.SqlClient;
using System.Configuration;
using System.Globalization;
using ICSharpCode.SharpZipLib.Checksums;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.GZip;
using System.IO;
using System.Web.UI.WebControls.WebParts;
public partial class AssessorWiseFeesReport : System.Web.UI.Page
{

    Guid gudUserID = CommonUtility.GetLoggedOnUserId();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //GetCountry();
            //brijal commented to load report from show button clink
            //GetData();
            // Session["UserID"] = Guid.NewGuid();
            GetRoalType();
            GetCountry();
            GetRegion();
        }
    }

    private DataSet GetDataSet()
    {
        DataSet objDs = null;
        try
        {
            objDs = new CandidateWorkflowBAL().GetAssessorWiseFeesReport();
        }
        catch (Exception ex)
        {
            lblErrorMessage.Text = "Error : " + ex.Message;
            ex.AddErrorToLog(); //throw new ApplicationException(exception.Message);
        }
        return objDs;
    }
    public DataSetAssessor GetAssessorWiseFeesReport()
    {
        DataSet objDS = new DataSet();
        DataTable objDt;
        DataSetAssessor dsCustomers = new DataSetAssessor();
        //brijal change for add parameter
        string tFrDt = string.Empty;
        string tToDt = string.Empty;
        if (txtDateFrom.Text != string.Empty)
            tFrDt = CommonUtility.ConvertDateyyyymmdd(txtDateFrom.Text);
        if (txtDateUpto.Text != string.Empty)
            tToDt = CommonUtility.ConvertDateyyyymmdd(txtDateFrom.Text);
        if (ddlRoleType.SelectedValue != "0" && !(ddlUserName.SelectedValue == "0" || ddlUserName.SelectedValue == string.Empty))
        {
            objDt = new CandidateWorkflowBAL().GetAssessorWiseFeesReport(ddlCountry.SelectedValue.ToInt(),
                                                                               ddlRegion.SelectedValue.ToInt(),
                                                                               tFrDt,
                                                                               tToDt,
                                                                               new Guid(ddlRoleType.SelectedValue),
                                                                               new Guid(ddlUserName.SelectedValue)).Tables[0];
        }else if (ddlRoleType.SelectedValue != "0" && (ddlUserName.SelectedValue == "0" || ddlUserName.SelectedValue == string.Empty))
        {
            objDt = new CandidateWorkflowBAL().GetAssessorWiseFeesReport(ddlCountry.SelectedValue.ToInt(),
                                                                              ddlRegion.SelectedValue.ToInt(),
                                                                              tFrDt,
                                                                              tToDt,
                                                                              new Guid(ddlRoleType.SelectedValue),
                                                                              null).Tables[0];
        }
        else if (ddlRoleType.SelectedValue == "0" && !(ddlUserName.SelectedValue == "0" || ddlUserName.SelectedValue == string.Empty))
        {
            objDt = new CandidateWorkflowBAL().GetAssessorWiseFeesReport(ddlCountry.SelectedValue.ToInt(),
                                                                              ddlRegion.SelectedValue.ToInt(),
                                                                              tFrDt,
                                                                              tToDt,
                                                                              null,
                                                                              new Guid(ddlUserName.SelectedValue)).Tables[0];
        }
        else
        {
            objDt = new CandidateWorkflowBAL().GetAssessorWiseFeesReport(ddlCountry.SelectedValue.ToInt(),
                                                                             ddlRegion.SelectedValue.ToInt(),
                                                                             tFrDt,
                                                                             tToDt,
                                                                             null,
                                                                             null).Tables[0];
        }

        //DataTable objDt = new CandidateWorkflowBAL().GetAssessorWiseFeesReport().Tables[0];

        //CommonUtility.ConvertDateyyyymmdd(txtDateFrom.Text), CommonUtility.ConvertDateyyyymmdd(txtDateUpto.Text), 1
        DataTableReader reader = new DataTableReader(objDt);
        dsCustomers.Tables["dsCustomers"].Load(reader);
        return dsCustomers;
    }

    private void GetData(params object[] param)
    {
        try
        {
            rvBar.LocalReport.ReportPath = Server.MapPath("~/report/FeesReport.rdlc");
            rvBar.LocalReport.EnableHyperlinks = true;
            DataSetAssessor dsBar = GetAssessorWiseFeesReport();
            ReportDataSource dsorBar = new ReportDataSource("DataSet1", dsBar.Tables[0]);

             rvBar.LocalReport.DataSources.Clear();
            rvBar.LocalReport.MapTileServerConfiguration.AppID = "AqCUTlVe8ueM3yJotaLUxSYK_hpVYx4NMkNYKwY0FhNYjIZc4Q0HjVyBt0dj-O3t";
            rvBar.LocalReport.DataSources.Add(dsorBar);
            lblErrorMessage.Text = string.Empty;
            //rvMap.ProcessingMode = ProcessingMode.Local;
            rvBar.ShowToolBar = true;
        }
        catch (Exception ex)
        {
            lblErrorMessage.Text = "Error : " + ex.Message;
            //ex.AddErrorToLog(); //throw new ApplicationException(exception.Message);
        }

    }
    private void Clear()
    {
        lblErrorMessage.Text = string.Empty;
    }
    protected void BtnClear_OnClick(object sender, EventArgs e)
    {
        try
        {
           
        }
        catch (Exception ex)
        {
            lblErrorMessage.Text = "Error : " + ex.Message;
        }
    }

    protected void ddlRoleType_SelectedIndexChanged(object sender, EventArgs e)
    {
        DataSet objDS = new DataSet();
        objDS = new UserMasterBAL().GetUserNameByRole(new Guid(ddlRoleType.SelectedValue)); ;
        CommonUtility.BindDropDown(ref ddlUserName, objDS, "FirstName", "UserId");
        CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlUserName);
        
    }

    protected void btnShow_Click(object sender, EventArgs e)
    {
        GetData();
    }
    private void GetRoalType()
    {
        ddlRoleType.DataSource = GetRoleAssessorDataSet();
        ddlRoleType.DataTextField = "RoleTitle";
        ddlRoleType.DataValueField = "RoleId";
        ddlRoleType.DataBind();
        ddlRoleType.Items.Insert(0, new ListItem("-- Select Role type --", "0"));
    }
    private DataSet GetRoleAssessorDataSet()
    {

        DataSet objDs = null;
        try
        {
            objDs = new RoleMasterBAL().GetRoleAssessor();
        }
        catch (Exception exception)
        {
            exception.AddErrorToLog(); //throw new ApplicationException(exception.Message);
        }
        return objDs;

    }
    private void GetCountry()
    {
        CountryMasterBAL objBAL = new CountryMasterBAL();
        DataSet ds = objBAL.GetCountry();
        if (ds != null)
        {
            ddlCountry.DataSource = ds;
            ddlCountry.DataTextField = "CountryName";
            ddlCountry.DataValueField = "CountryID";
            ddlCountry.DataBind();
            ddlCountry.Items.Insert(0, new ListItem("--Select Country--", "0"));
        }
    }
    private void GetRegion()
    {
        RegionMasterBAL objBAL = new RegionMasterBAL();
        DataSet ds = objBAL.GetRegionMaster();
        if (ds != null)
        {
            ddlRegion.DataSource = ds;
            ddlRegion.DataTextField = "RegionName";
            ddlRegion.DataValueField = "RegionID";
            ddlRegion.DataBind();
            ddlRegion.Items.Insert(0, new ListItem("--Select Region--", "0"));
        }
    }
}

